<template>
  <van-form @submit="onSubmit">
    <van-field
        v-model="ediUser.currentValue"
        :name="ediUser.editkey"
        :label="ediUser.editName"
        :placeholder="`请输入${ediUser.editName}`"
    />

    <!--    // 上传图像-->
    <!--    <div v-if="ediUser.editkey==='avtarUrl'">-->
    <!--      <van-field name="uploader" label="头像上传">-->
    <!--        <template #input>-->
    <!--&lt;!&ndash;          <van-uploader :v-model="fileList" reupload />&ndash;&gt;-->
    <!--          <van-uploader v-model="fileList" reupload max-count="2" :after-read="afterRead"/>-->

    <!--        </template>-->
    <!--      </van-field>-->
    <!--    </div>-->


    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>

</template>


<script setup lang="ts">
import {useRoute, useRouter} from "vue-router";
import {ref} from "vue";
import myAxios from "../../plugins/myAxios.ts";
import {showFailToast, showSuccessToast} from "vant";


const route = useRoute();
const router = useRouter();

const ediUser = ref({
  editkey: route.query.editkey as string,
  editName: route.query.editName as string,
  currentValue: route.query.currentValue as string
})

// const fileList = ref([
//   {url: ediUser.value.currentValue},
// ]);

// 提交
const onSubmit = async () => {
  const res = await myAxios.post('/user/update', {
    [ediUser.value.editkey]: ediUser.value.currentValue
  })

  if ( res.data > 0) {
    router.back();
  } else {
    showFailToast('更新失败')
  }
};


// 上传图像
// const afterRead = (file) => {
//   console.log(file.file);
//   } ;


console.log(route.query)

</script>


<style scoped>

</style>